import request from '@/utils/request'
import { camelCaseObject } from '@/libs/object'

const AUTH_PREFIX_V1 = `/api/v1/auth`

export function login(params) {
  return request.post(`${AUTH_PREFIX_V1}/users/login`, params)
}

export function getUserInfoByToken() {
  return request.get(`${AUTH_PREFIX_V1}/users/token`).then(res => camelCaseObject(res))
}

export function getUserTokenBySsoSession() {
  return request.get(`${AUTH_PREFIX_V1}/users/sso`).then(res => camelCaseObject(res))
}

export function getUsersAll() {
  return request.get(`${AUTH_PREFIX_V1}/users/all`)
}

export function getUsers(params) {
  return request.get(`${AUTH_PREFIX_V1}/users`, { params })
}

export function editUser(userId, params) {
  return request.put(`${AUTH_PREFIX_V1}/users/${userId}`, params)
}

export function getUser(userId) {
  return request.get(`${AUTH_PREFIX_V1}/users/${userId}`)
}

export function getDepartments(params) {
  return request.get(`${AUTH_PREFIX_V1}/departments`, { params }).then(res => camelCaseObject(res))
}

export function logout() {
  return request({
    url: '/vue-admin-template/user/logout',
    method: 'post'
  })
}
